

package jetbrains.buildServer.server.rest.request;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import jetbrains.buildServer.server.rest.model.server.AuthSettings;
import jetbrains.buildServer.server.rest.service.rest.ServerAuthRestService;
import org.jetbrains.annotations.NotNull;

@Path(ServerAuthRequest.API_SUB_URL)
@Api("Server Authentication Settings")
public class ServerAuthRequest {
  public static final String API_SUB_URL = Constants.API_URL + ServerRequest.SERVER_REQUEST_PATH + "/authSettings";

  @Context private ServerAuthRestService myServerAuthRestService;

  @GET
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  @ApiOperation(value = "Get authentication settings.", nickname = "getAuthSettings")
  public AuthSettings getAuthSettings() {
    return myServerAuthRestService.getAuthSettings();
  }

  @PUT
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  @ApiOperation(value = "Set authentication settings.", nickname = "setAuthSettings")
  public AuthSettings setAuthSettings(AuthSettings settings) {
    return myServerAuthRestService.setAuthSettings(settings);
  }

  public void initForTests(
    @NotNull ServerAuthRestService serverAuthRestService) {
    myServerAuthRestService = serverAuthRestService;
  }
}